import datastructurelike.ListNode;

import java.util.HashMap;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Like
 * Date: 2021-04-12
 * Time: 8:29
 */

public class mergekuohao {


    public  boolean fun(String s) {

        if(s==null){
            return false;
        }

        if(s.length()%2==1){
            return false;
        }
        HashMap<Character, Character> map = new HashMap<Character, Character>(){{
            put(']','[');
              put('}','{');
              put(')','(');}

        };


        Stack<Character> stack = new Stack<>();
        stack.push(s.charAt(0));
        for(int i=1;i<s.length();i++){
            char b=s.charAt(i);
            if(map.containsKey(b)){
                if(stack.isEmpty() || !stack.peek().equals(map.get(b))){
                    return false;
                }stack.pop();
            }
            else{stack.push(b);}
        }
        if (stack.isEmpty()){return true;}
        else {return false;}


    }
    public ListNode mergeTwoLists (ListNode l1, ListNode l2) {
        if(l1==null)return l2;
        if(l2==null)return l1;
        ListNode node = new ListNode(1);
        while (l1==null || l2==null){
            if(l1.val<=l2.val){
                node.next=l1;
                node=node.next;
                l1=l1.next;

            }if(l1.val>l2.val){
                node.next=l2;
                node=node.next;
                l2=l2.next;

            }
        }
        if(l1!=null) {node.next=l2;}
        if(l2!=null) {node.next=l1;}
        return node;
    }



    public static void main(String[] args) {
        String s="[]()";
        mergekuohao mergekuohao = new mergekuohao();
        boolean ans=mergekuohao.fun(s);
        System.out.println(ans);
    }

}

